﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.DAL;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.DAL
{
    public class StockOutDetailDAL:IStockOutDetailDAL
    {
        #region IStockOutDetailDAL 成员

        //public IDataReader Select()
        //{

        //}
        public IDataReader Select()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public IDataReader SelectByNum(string StockOutNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_StockOutDetail_Select", new SqlParameter[] { new SqlParameter("@StockOutNum", StockOutNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public DataTable Select(string StockOutNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_StockOutDetail_Select", new SqlParameter[] { new SqlParameter("@StockOutNum", StockOutNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }        
        }

        public int Insert(string StockOutNum,int DrugNum,int RealQuantity,float OutportPrice,float Amount)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockOutNum",StockOutNum),
                    new SqlParameter("@DrugNum",DrugNum),
                    new SqlParameter("@RealQuantity",RealQuantity),    
                    new SqlParameter("@OutportPrice",OutportPrice),
                    new SqlParameter("@Amount",Amount)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockOutDetail_Insert", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Update(string StockOutNum, int DrugNum, int RealQuantity, float OutportPrice, float Amount)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockOutNum",StockOutNum),
                    new SqlParameter("@DrugNum",DrugNum),
                    new SqlParameter("@RealQuantity",RealQuantity),    
                    new SqlParameter("@OutportPrice",OutportPrice),
                    new SqlParameter("@Amount",Amount)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockOutDetail_Update", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Delete(string StockOutNum, int DrugNum)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockOutNum",StockOutNum),
                    new SqlParameter("@DrugNum",DrugNum)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockOutDetail_Delete", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Delete(string StockOutNum)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@ StockOutNum", StockOutNum)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockOutDetail_Delete", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        #endregion
    }
}
